/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.brain.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.brain.entity.BUserOrprInfo;
import com.thinkgem.jeesite.modules.brain.service.BUserOrprInfoService;

/**
 * 用户答题操作记录Controller
 * @author 程展峰
 * @version 2021-09-22
 */
@Controller
@RequestMapping(value = "${adminPath}/brain/bUserOrprInfo")
public class BUserOrprInfoController extends BaseController {

	@Autowired
	private BUserOrprInfoService bUserOrprInfoService;
	
	@ModelAttribute
	public BUserOrprInfo get(@RequestParam(required=false) String id) {
		BUserOrprInfo entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = bUserOrprInfoService.get(id);
		}
		if (entity == null){
			entity = new BUserOrprInfo();
		}
		return entity;
	}
	
	@RequiresPermissions("brain:bUserOrprInfo:view")
	@RequestMapping(value = {"list", ""})
	public String list(BUserOrprInfo bUserOrprInfo, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<BUserOrprInfo> page = bUserOrprInfoService.findPage(new Page<BUserOrprInfo>(request, response), bUserOrprInfo); 
		model.addAttribute("page", page);
		return "modules/brain/bUserOrprInfoList";
	}

	@RequiresPermissions("brain:bUserOrprInfo:view")
	@RequestMapping(value = "form")
	public String form(BUserOrprInfo bUserOrprInfo, Model model) {
		model.addAttribute("bUserOrprInfo", bUserOrprInfo);
		return "modules/brain/bUserOrprInfoForm";
	}

	@RequiresPermissions("brain:bUserOrprInfo:edit")
	@RequestMapping(value = "save")
	public String save(BUserOrprInfo bUserOrprInfo, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, bUserOrprInfo)){
			return form(bUserOrprInfo, model);
		}
		bUserOrprInfoService.save(bUserOrprInfo);
		addMessage(redirectAttributes, "保存用户答题操作记录成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bUserOrprInfo/?repage";
	}
	
	@RequiresPermissions("brain:bUserOrprInfo:edit")
	@RequestMapping(value = "delete")
	public String delete(BUserOrprInfo bUserOrprInfo, RedirectAttributes redirectAttributes) {
		bUserOrprInfoService.delete(bUserOrprInfo);
		addMessage(redirectAttributes, "删除用户答题操作记录成功");
		return "redirect:"+Global.getAdminPath()+"/brain/bUserOrprInfo/?repage";
	}

}